# -*- coding: utf-8 -*-

###############################################################################
# Copyright [2010] [Roberto Carrasco - rcarrasco@talentus.cl]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 
###############################################################################

"""About dialog code

Code is here just for clarity in the main
"""

import pygtk
pygtk.require('2.0')
import gtk

class ProgressWindow:
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file('./UI/ProgressWindow.ui')
        self.pw = self.builder.get_object('ProgressWindow')
        self.pw.connect('delete_event', lambda w, e: True)
        self.button = self.builder.get_object('closeProgressWindow')
        self.button.connect('clicked', lambda w: self.pw.hide())
        self.textView = self.builder.get_object('progressText')
        self.textBuffer = self.textView.get_buffer()

    def begin(self):
        self.button.set_sensitive(False)
        self.textBuffer.set_text('')
        self.pw.show()

    def append(self, text):
        self.textBuffer.insert(self.textBuffer.get_end_iter(), text)
        self.textView.scroll_to_iter(self.textBuffer.get_end_iter(), 0)

    def end(self):
        self.button.set_sensitive(True)
